<%@codepage="65001"%> 
<!--#include file="../Include/Conn.asp" -->
<!--#include file="seeion.asp"-->
<!--#include file="page.asp" -->
<%call chkAdmin("|18") %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" id="css" href="images/style.css">
<title>订单管理</title>
<script language="javascript"> 
<!-- 
function CheckAll(){ 
 for (var i=0;i<eval(form1.elements.length);i++){ 
  var e=form1.elements[i]; 
  if (e.name!="allbox") e.checked=form1.allbox.checked; 
 } 
} 
--> 
</script> 
<style type="text/css">
body,td,th {font-family: "Microsoft YaHei", Arial, "宋体";}
</style>
</head>
<body>
<%if request.querystring("action")="admin" then%>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
  <tr>
    <td height="30" class="topnav"><div>订单管理</div></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">
 <table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="stable">
  <form id="form1" name="form1" method="post" action="admin_orders.asp?del=checkbox">
<div style="text-align:left;height:25px; padding:0px 10px 0px 10px;"> 
      <select name="ssfl" class="sel" id="jumpMenu" onChange="window.open(this.options[this.selectedIndex].value,'_self')">
      <option>---分类查看---</option>
      <option value="?action=admin&lxid=">---全部订单---</option>
      <option value="?action=admin&lxid=1">---新订单---</option>
      <option value="?action=admin&lxid=2">---已处理---</option>
      </select>
</div>
<thead><tr>
  <td width="30" align="center" class="td"><input name="ID" type="checkbox"/></td>
  <td width="60" align="center" class="td">ID</td>
  <td width="146" align="center" class="td">订单号</td>
  <td class="td"> 订单名称</td>
  <td width="137" height="25" align="center" class="td">订单金额</td>
  <td width="138" align="center" class="td">订单状态</td>
<td width="160" align="center" class="td">订单时间</td>
<td width="80" align="center" class="td">管理</td>
<td width="80" align="center" class="td">删除</td>
</tr></thead>
<%id=request.QueryString("lxid") 
set rs=server.createobject("adodb.recordset")
if id<>"" then
exec="select * from [orders] where state="&id&" order by id desc" 
else
exec="select * from [orders] order by id desc"  
end if
rs.open exec,conn,1,1 
if rs.eof then
response.write ("<div style=""padding:10px;"">暂无记录!</div>")
else
rs.PageSize =20 '每页记录条数
iCount=rs.RecordCount '记录总数
iPageSize=rs.PageSize
maxpage=rs.PageCount 
page=request("page")
if Not IsNumeric(page) or page="" then
page=1
else
page=cint(page)
end if
if page<1 then
page=1
elseif  page>maxpage then
page=maxpage
end if
rs.AbsolutePage=Page
if page=maxpage then
x=iCount-(maxpage-1)*iPageSize
else
x=iPageSize
end if	
for i=1 to rs.pagesize
title=split(rs("title"),"|")
Cid=split(rs("Cid"),"|")
num=split(rs("number"),"|")
xrmb=split(rs("xrmb"),"|")
%>
<tr>
  <td align="center" class="td"><input name="ID" type="checkbox" id="ID" value="<%=rs("id")%>" /></td>
  <td align="center" class="td"><input type="text" class="inp" style="text-align:center; width:40px" value="<%=rs("id")%>" readonly/></td>
  <td align="center" class="td"><a href="?action=xiugai&id=<%=rs("id")%>"><b><%=rs("OrderNo")%></b></a></td>
  <td class="td">&nbsp;</td>
  <%if rs("state")=1 then
  ddzt="等待买家付款"
  elseif rs("state")=2 then
  ddzt="买家已付款，等待发货"
  elseif rs("state")=3 then
  ddzt="卖家已发货，等待确认收货"
  elseif rs("state")=8 then
  ddzt="交易完成"
  else
  ddzt="订单出现异常"
  end if %> 
  <td height="25" align="center" class="td"><%=rs("rmb")%></td>
  <td height="25" align="center" class="td"><%=ddzt%></td>
<td align="center" class="td"><%=rs("data")%></td>
<td align="center" class="td">
<input type="button" name="Submit3" value="管理订单" onclick="window.location.href='?action=xiugai&id=<%=rs("id")%>' "  class="btn"/></td>
<td align="center" class="td">
<input type="button" name="Submit" value="删除" onclick="javascript:if(confirm('确定删除该订单？删除后不可恢复!')){window.location.href='admin_orders.asp?id=<%=rs("id")%>&amp;del=ok';}else{history.go(0);}"  class="btn"/>
</td>
</tr>
<%rs.movenext 
if rs.eof then exit for 
next 
end if%>
<tr>
<td width="28" height="30" align="center" style="padding-left:5px;"><input type="checkbox" name="allbox" onclick="CheckAll()" /></td>
<td width="40" height="30" align="center" style="padding-left:5px;">全选</td>
<td width="293" colspan="2"><label>
  <select name="lxid" class="sel">
  <option selected="selected" value="">操作类型</option>
  <option value="1">标记为未付款</option>
  <option value="2">标记为已付款</option>
  <option value="3">标记为已发货</option>
  <option value="8">标记为完交易</option>
  <option value="4">订单异常</option>
  </select>
  <input type="submit" name="button" id="button" value="提交"  class="btn"/>
  </label>

  累计收入:<font style="font-size:24px; color:#F00; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif">￥元</font>
  
</td>
<td colspan="5"><%call PageControl(iCount,maxpage,page)
rs.close
set rs=nothing%></td>
</form>  
    </table></td>
  </tr>
</table>
<% end if %>
<% if request.querystring("action")="xiugai" then
id=request.QueryString("id")
if id="" or not isnumeric(id) then
Response.Write "<script>alert('参数错误！');history.go(-1);</script>" 
Response.End()
end if
exec="select * from [orders] where id="& id 
set rs=server.createobject("adodb.recordset") 
rs.open exec,conn,1,1 
if rs.eof and rs.bof then
Response.Write "<script>alert('参数不正确，ID值不存在！');history.go(-1);</script>" 
Response.End()
end if
title=split(rs("title"),"|")
Cid=split(rs("Cid"),"|")
num=split(rs("number"),"|")
xrmb=split(rs("xrmb"),"|")
%>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#ccccccc">
  <tr>
    <td height="30" class="topnav"><div>查看订单</div></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">
	<form name="add" method="post" action="?id=<%=rs("id")%>&xiugai=ok">
    <table width="100%"  border="0" cellpadding="6" cellspacing="0" bordercolor="#EDEDED" class="stable">
 <tr>
   <td width="11%" align="right">订单编号：</td>
   <td colspan="2"><%=rs("OrderNo")%></td>
   </tr>
  <tr>
   <td width="11%" align="right">支付宝交易号：</td>
   <td colspan="2"><%=rs("trade_no")%></td>
   </tr>
 <tr>
   <td width="11%" align="right">订单时间：</td>
   <td><%=rs("data")%></td>
 </tr>
  <tr>
   <td width="11%" align="right">交易状态：</td>
   <td><%=ddzt%></td>
 </tr>
<tr>
  <td align="right">产品列表：</td>
  <td><table width="50%"  border="1" cellpadding="6" cellspacing="0" bordercolor="#EDEDED" style="border-collapse:collapse;line-height:25px; text-indent:3px; margin:5px 0;">
    <tr bgcolor="#E7F7FA">
      <td colspan="2" align="center"> 产品名称</td>
      <td width="100" align="center">单价</td>
      <td width="100" align="center">数量</td>
      <td width="100" align="center">金额</td>
    </tr>
<%for ii=0 to ubound(title)%>
    <tr>    
      <td align="center">图片</td>
      <td align="left"><%=title(ii)%></td>
      <td align="center"><%=lz_money(xrmb(ii))%></td>
      <td align="center"><%=num(ii)%></td>
      <td align="center"><%=lz_money(xrmb(ii)*num(ii))%></td>
    </tr>
<%next%>
  </table></td>
</tr>
<tr>
  <td align="right">付款金额：</td>
  <td><font style="font-size:18px; color:#F00"><%=lz_money(Rs("rmb"))%></font>元</td>
  </tr>
  <tr>
  <td width="11%" height="25" align="right" class="td">付款金额：</td>
        <td colspan="2" class="td"><input name="rmb" type="text" class="inp" <% If rs("state")<>1 Then %>style="background:#E4E4E4"<% End If %> value="<%=rs("rmb")%>"<% If rs("state")<>1 Then %> readonly<% End If %> /></td>
      </tr>
<tr>
  <td align="right">收货地址：</td>
  <td colspan="2"><%=rs("name")%>，<%=rs("tel")%>，<%=rs("address")%>，(QQ:<%=rs("QQ")%>)</td>
 </tr>
<tr>
  <td align="right">快递公司：</td>
  <td colspan="2"><%=kd_title(rs("kddm"))%></td>
</tr>
<tr>
  <td align="right">快递单号：</td>
  <td colspan="2">	<%=rs("kddm")%></td>
</tr>
<tr>
  <td align="right">其它说明：</td>
  <td colspan="2"><%=rs("sm")%></td>
</tr>

<tr>
      <td height="25" align="right" class="td">备注信息</td>
      <td colspan="2" class="td"><textarea name="bz" cols="50" rows="3" class="tex" ></textarea></td>
    </tr>
	<tr>
      <td height="25" align="right" class="td">物流单号</td>
      <td colspan="2" class="td"><select name="kddm" class="tex">
            <option selected="selected" value="">快递公司</option>
			<%set rsc=server.CreateObject("adodb.recordset")
            rsc.open "select * from orders_kd order by px_id asc",conn,1,1
            while not rsc.eof
            if rs("kddm")=rsc("kddm") then
            response.Write("<option value="""&rsc("kddm")&""" selected>" & rsc("title") & "</option>")
            else
            response.Write("<option value="""&rsc("kddm")&""">" & rsc("title") & "</option>")
            end if
            rsc.movenext
            wend
            rsc.close
            set rsc=nothing%>
          </select><input name="kddh" type="text" class="inp" value="<%=rs("kddh")%>" placeholder="请输入快递单号" /></td>
    </tr>
    <tr>
      <td height="25" align="right" class="td">订单状态</td>
      <td colspan="2" class="td"><select name="state" class="sel">
            <option selected="selected" value="">操作类型</option>
            <option value="1" <%if rs("state")="1" then%>selected<%end if%>>标记为未付款</option>
            <option value="2" <%if rs("state")="2" then%>selected<%end if%>>标记为已付款</option>
            <option value="3" <%if rs("state")="3" then%>selected<%end if%>>标记为已发货</option>
            <option value="8" <%if rs("state")="8" then%>selected<%end if%>>标记为完交易</option>
            <option value="4" <%if rs("state")="4" then%>selected<%end if%>>订单异常</option>
          </select></td>
    </tr>
    <tr>
      <td height="25" align="right" class="td">&nbsp;</td>
      <td  colspan="2"class="td"><input type="button" name="Submit3" value="返回订单列表" onclick="window.location.href='admin_orders.asp?action=admin'" class="btn"/>  <input type="submit" name="button" id="button" value="处理订单"  class="btn"/></td>
    </tr>
    
</table>
  </form>  	
</td>
  </tr>
</table>
<% end if %>
</body>
</html>
<%
if request("del")="ok" then
set rs=server.createobject("adodb.recordset")
id=Request.QueryString("id")
sql="select * from orders where id="&id
rs.open sql,conn,2,3
rs.delete
rs.update
Response.Write "<script>alert('当前订单删除成功！');window.location.href='admin_orders.asp?action=admin';</script>"
end if 

if Request.QueryString("del")="checkbox" then
if Request("id")="" then
Response.Write "<script>alert('错误!请选择要操作的记录!');window.location.href='admin_orders.asp?action=admin';</script>" 
response.end()
end if
dim sql
lx=request.Form("lxid")
if lx="" then
Response.Write "<script>alert('错误!请选择操作类型!');window.location.href='admin_orders.asp?action=admin';</script>" 
response.end
end if
if lx=1 then
sql="update orders set state=1 where id in ("&Request("id")&")" 
conn.execute(sql) 
elseif lx=2 then 
sql="update orders set state=2 where id in ("&Request("id")&")" 
conn.execute(sql)
elseif lx=3 then
sql="update orders set state=3 where id in ("&Request("id")&")" 
conn.execute(sql) 
elseif lx=8 then 
sql="update orders set state=8 where id in ("&Request("id")&")" 
conn.execute(sql)
elseif lx=4 then 
sql="update orders set state=8 where id in ("&Request("id")&")" 
conn.execute(sql) 
else
sql="delete from orders where id in ("&Request("id")&")"
conn.Execute ( sql )
end if
conn.close
set conn=nothing
Response.Write "<script>alert('恭喜!操作成功!');window.location.href='admin_orders.asp?action=admin';</script>" 
end if

if Request.QueryString("xiugai")="ok" then 
id=request("id")
bz=request.form("bz")
rmb=request.form("rmb")
kuaidi=request.form("kuaidi")
state=request.form("state")
	if id="" or not isnumeric(id) then
Response.Write "<script>alert('参数错误！');history.go(-1);</script>" 
	Response.End()
	end if
	SQL="Select * from orders where id="&id
	set rs=server.createobject("adodb.recordset")
	rs.open SQL,conn,1,3
	if rs.eof and rs.bof then
Response.Write "<script>alert('参数不正确，ID值不存在！');history.go(-1);</script>" 
	Response.End()
	end if
rs("rmb")=rmb
rs("kddh")=request.form("kddh")
rs("kddm")=request.form("kddm")
rs("state")=state
rs("bz")=bz
rs.update 
rs.close 
response.write "<script>alert('订单修改成功！');window.location.href='admin_orders.asp?action=admin';</script>" 
end if
%> 